Attribute VB_Name = "Module_ItmVen"
Public Add_ItmVenRowid As String
'
Public Add_ItmCode As String
Public Add_ItmDesc As String
'
Public Add_StartDate As String
Public Add_EndDate As String

Public Add_VendorDesc As String
Public Add_VendorCode As String

Function GetItmMsg(v As VisM, Itmdesc As String) As String
    v.P0 = Itmdesc
    Call Restore_Connect(v)
    v.Execute "$$GetItmMsg^DHCSTITMVEN(P0)"
    If v.Error <> 0 Then
        MsgBox "ERROR:" + v.ErrorName
        Exit Function
    End If
    GetItmMsg = v.PLIST
End Function

Function AddItmVen(v As VisM, itmcode As String, vendor_desc As String, price As String, _
                   startdate As String, enddate As String, manf As String, cardr As String)
    
    v.P0 = itmcode
    v.P1 = vendor_desc
    v.P2 = price
    v.P3 = startdate
    v.P4 = enddate
    v.P5 = manf
    v.P6 = cardr
    Call Restore_Connect(v)
    v.Execute "$$Insert^DHCSTITMVEN(P0,P1,P2,P3,P4,P5,P6)"
    If v.Error <> 0 Then
        MsgBox "Error:" + v.ErrorName
        Exit Function
    End If
    AddItmVen = v.Value
End Function

Function GetItmVen(v As VisM, itmven_rowid As String) As String
    v.P0 = itmven_rowid
    Call Restore_Connect(v)
    v.Execute "$$Select^DHCSTITMVEN(P0)"
    If v.Error <> 0 Then
        MsgBox "Error:" + v.ErrorName
        Exit Function
    End If
    GetItmVen = v.Value
End Function

Function IsItmVenExists(v As VisM, ByVal Itmdesc As String) As String
    v.P0 = Itmdesc
    Call Restore_Connect(v)
    v.Execute "$$ChkItmVenExist^DHCSTITMVEN(P0)"
    If v.Error <> 0 Then
        MsgBox "Error:" + v.ErrorName
        Exit Function
    End If
    IsItmVenExists = v.Value
End Function
Sub SetRelativeManfToDDLB(v As VisM, cb As ComboBox, ByVal inputstr As String)
    v.P0 = inputstr
    Call Restore_Connect(v)
    v.Execute "$$GetRelativeManf^DHCSTITMVEN(P0)"
    If v.Error <> 0 Then
        MsgBox "Error:" + v.ErrorName
        Exit Sub
    End If
    Dim cnt As Integer
    Dim i As Integer
    Dim manf_dr As Long
    Dim manf As String
    
    cnt = Val(v.Value)
    If cnt > 0 Then
        cb.Clear
        Dim str_arr() As String
        Dim str_arr2() As String
        str_arr = Split(v.PLIST, v.PDELIM)
        For i = 0 To UBound(str_arr)
            str_arr2 = Split(str_arr(i), "&")
            manf_dr = Val(str_arr2(0))
            manf = str_arr2(1)
            cb.AddItem (manf)
            cb.ItemData(i) = manf_dr
        Next
    End If
End Sub
Function InsertItmven(v As VisM, ByVal tmpdata As String, ByVal tmpPubDR As String, ByVal tmpstype As String)
    v.P1 = tmpdata
    v.P2 = tmpPubDR
    v.P3 = tmpstype
    Call Restore_Connect(v)
    v.Execute "$$InsertItmVen^DHCSTITMVEN(P1,P2,P3)"
    If v.Error <> 0 Then
        MsgBox "error" + v.ErrorName
        Exit Function
    End If
    InsertItmven = v.Value
End Function
